//
//  XBTabbarController.swift
//  Sina
//
//  Created by 周旭斌 on 2017/3/23.
//  Copyright © 2017年 周旭斌. All rights reserved.
//

import UIKit

class XBTabbarController: UITabBarController {
    
    let mainTabBar = XBTabBar();

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        // 添加子控制器
        addChildViewControllers();
        
        setValue(mainTabBar, forKeyPath: "tabBar");
    }
    
    // MARK:添加子控制器
    private func addChildViewControllers() {
        setControllerinfo(XBNavBaseController(rootViewController: XBHomeController()), title: "首页", normalImage: "tabbar_home", highlightedImage: "tabbar_home_highlighted");
        setControllerinfo(XBNavBaseController(rootViewController: XBDiscoveryController()), title: "发现", normalImage: "tabbar_discover", highlightedImage: "tabbar_discover_highlighted");
        setControllerinfo(XBNavBaseController(rootViewController: XBComposeController()), title: "", normalImage: "", highlightedImage: "");
        setControllerinfo(XBNavBaseController(rootViewController: XBMessageController()), title: "消息", normalImage: "tabbar_message_center", highlightedImage: "tabbar_message_center_highlighted");
        setControllerinfo(XBNavBaseController(rootViewController: XBProfileController()), title: "我", normalImage: "tabbar_profile", highlightedImage: "tabbar_profile_highlighted");
    }
    
    private func setControllerinfo(_ controller : UIViewController, title : String, normalImage : String, highlightedImage : String) {
        controller.title = title;
        controller.tabBarItem.image = UIImage.init(named: normalImage);
        controller.tabBarItem.selectedImage = UIImage.init(named: highlightedImage);
        addChildViewController(controller);
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
